﻿/**********************************************************************
* Description:	Concrete implementation of ICachable that utilizes the Application Cache
* Created By:   Jason Offutt @ Central Christian Church of the East Valley
* Date Created:	7/6/2009
*
* $Workfile: HttpCache.cs $
* $Revision: 5 $ 
* $Header: /trunk/Arena.Custom.Cccev/Arena.Custom.Cccev.FrameworkUtils/BLL/HttpCache.cs   5   2009-10-22 09:57:25-07:00   JasonO $
* 
* $Log: /trunk/Arena.Custom.Cccev/Arena.Custom.Cccev.FrameworkUtils/BLL/HttpCache.cs $
*  
*  Revision: 5   Date: 2009-10-22 16:57:25Z   User: JasonO 
*  
*  Revision: 4   Date: 2009-10-22 16:57:03Z   User: JasonO 
*  
*  Revision: 3   Date: 2009-08-18 15:29:36Z   User: JasonO 
*  
*  Revision: 2   Date: 2009-07-06 21:12:15Z   User: JasonO 
*  Adding more common interface elements to caching contracts. 
*  
*  Revision: 1   Date: 2009-07-06 18:50:52Z   User: JasonO 
*  Abstracting caching. 
**********************************************************************/

using System;
using System.Web;
using System.Web.Caching;
using Arena.Custom.Cccev.FrameworkUtils.Interfaces;

namespace Arena.Custom.Cccev.FrameworkUtils.BLL
{
    public sealed class HttpCache : ICachable
    {
        private static volatile HttpCache instance;

        /// <summary>
        /// Static implementation to limit how Cache is accessed.
        /// </summary>
        public static HttpCache Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new HttpCache();
                }

                return instance;
            }
        }

        public object Cache
        {
            get
            {
                if (HttpContext.Current == null)
                {
                    throw new NullReferenceException("If using this functionality outside of ASP.NET, set the CacheType of the caller to CacheType.Dictionary.");
                }

                return HttpContext.Current.Cache;
            }
        }

        public int Count
        {
            get { return ((Cache) Cache).Count; }
        }

        public object Get(string key)
        {
            return ((Cache) Cache).Get(key);
        }

        public void Insert(string key, object value)
        {
            ((Cache) Cache).Insert(key, value);
        }

        public void Remove(string key)
        {
            ((Cache) Cache).Remove(key);
        }

        private HttpCache()
        {
        }
    }
}
